using System;
using System.Text;
using IIS.Remoting.Shared;
using ODX.Core;

namespace IIS.Remoting.Server
{
    public class PersonService : MarshalByRefObject, IPersonService
    {

        public void SignPerson(ref Person person)
        {
            // Some dummy signatyre algorithm 
            person.Signature =
                Convert.ToBase64String(
                    Encoding.Unicode.GetBytes(person.Name));
        }

        public void Save(Person person)
        {
            // Create a copy of global session to process each client request
            // through a separate session. It also possible to recreate session.
            Session threadSession =
                GlobalSessionKeeper.ConnectedSession.Clone();

            // Person is registered on a temporary session
            // so we need to merge it to a connected session.
            threadSession.Merge(person);

            // And, finally, save person!
            threadSession.Save();
        }
    }

    public class GlobalSessionKeeper
    {
        private static Session connectedSession;
        public static Session ConnectedSession
        {
            get { return connectedSession; }
            set { connectedSession = value; }
        }

    }
}
